<!-- page heading start-->
<div class="page-heading">
    <h3>
        财务奖金分配管理系统
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">
                    增加
                </button>
                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal1">
                    导入
                </button>
            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered" style="width: 20%;float: left">
                    <tr>
                        <td><a href="/User/Tool/award">全部工作室</a><a class="btn btn-success" href="/User/Tool/room" style="float: right">新增</a></td>
                    </tr>
                    <?php
                foreach($room as $room_v){
                    echo "<tr>
                    <td style='border:0px;'><a href='/User/Tool/award?room_id=" . $room_v['id'] . "'>" . $room_v['name'] . "</a></td>
                    </tr>";
                    }
                    ?>
                </table>
                <div class="input-group" style="width: 100px;float: right;margin-right: 50px;">
                    <button class="btn btn-success"  onclick="return download();">导出</button>
                </div>
                <div class="input-group" style="width: 300px;float: left;margin-left: 20px;">
                    <input class="form-control input-lg date-picker1"autocomplete="off" name="startdate" id="sdate" value="<?php echo I('get.sdate', '', '');?>"
                           placeholder="请输入要选择的月份">
                    <span class="input-group-addon btn btn-primary" onclick="submit_sdate()">搜索</span>
                </div>
                <table class="table table-hover general-table table-bordered" style="width: 79%;float: right;">
                    <thead>
                    <tr>
                        <th width="10%">时间</th>
                        <th width="20%">工作室</th>
                        <th width="12%">奖金</th>
                        <th width="12%">费用</th>
                        <th width="8%">状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['year'] . "年" . $val['month'] . "月";?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['room_name'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['award'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['fee'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php
                                if($val['status'] != 2){
                                    switch($val['status']){
                                        case 1:
                                            echo "待提交";break;
                                        case 2:
                                            echo "已导出";break;
                                        case 3:
                                            echo "待审核";break;
                                        case 4:
                                            echo "待审批";break;
                                        case 5:
                                            echo "已完成";break;
                                    }
                                }else{
                                    switch($val['remain_status']){
                                        case 1:
                                            echo "待提交(已导出)";break;
                                        case 2:
                                            echo "已导出";break;
                                        case 3:
                                            echo "待审核(已导出)";break;
                                        case 4:
                                            echo "待审批(已导出)";break;
                                        case 5:
                                            echo "已完成(已导出)";break;
                                    }
                                }

                            ?>
                            </span>
                        </td>
                        <td>
                            <div>
                                <button class="btn btn-primary" onclick="return show(this)"
                                        data-id="<?php echo $val['id'];?>"
                                        data-award="<?php echo $val['award'];?>" data-fee="<?php echo $val['fee'];?>"
                                        data-year="<?php echo $val['year'];?>" data-month="<?php echo $val['month'];?>"
                                        data-roomId="<?php echo $val['room_id'];?>"
                                        data-roomName="<?php echo $val['room_name'];?>">
                                    编辑
                                </button>
                                <button class="btn btn-success" onclick="return show_dtl(this)"
                                        data-year="<?php echo $val['year'];?>" data-month="<?php echo $val['month'];?>"
                                        data-roomId="<?php echo $val['room_id'];?>"
                                        data-roomName="<?php echo $val['room_name'];?>">
                                    详情
                                </button>
                                <a class="btn btn-danger" href="#"
                                   onclick="<?php echo 'return delete_data(' . $val['id'] .')';?>">删除</a>
                                <a class="btn btn-default" href="#"
                                   onclick="<?php echo 'return renew_data(' . $val['id'] .')';?>">撤回</a>
                            </div>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <input type="hidden" id="id" value="">
                <div class="row">
                    <label class="form-inline">奖金时间:
                        <input class="form-control date-picker" style="width: 300px;" name="date" id="date"
                               placeholder="请选择时间">
                    </label>
                </div>
                <div class="row">
                    <label class="form-inline">工作室名:
                        <select class="form-control" style="width: 300px;" name="room_id" id="room_id">
                            <option value="0">--无--</option>
                            <?php foreach($room as $room_v){ ?>
                            <option value="<?php echo $room_v['id'];?>"><?php echo $room_v['name'];?></option>
                            <?php } ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">奖金额度:
                        <input type="text" class="form-control" style="width: 300px;" name="award" id="award"></label>
                </div>
                <div class="row">
                    <label class="form-inline">费用额度:
                        <input type="text" class="form-control" style="width: 300px;" name="fee" id="fee"></label>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="update();">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <form enctype="multipart/form-data" action="/User/Tool/awardImport" method="post">
                    <input type="file" name="import">
                    <a href="/Public/file/Book1.xlsx">样例下载</a><input class="btn btn-success" type="submit">
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">模态框（Modal）标题</h4>
            </div>
            <div class="modal-body" id="myModal2_body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    function update() {
        var id = $("#id").val();
        var award = $("#award").val();
        var fee = $("#fee").val();
        var room_id = $("#room_id").val();
        var date = $("#date").val();
        $.ajax({
            data: {id: id, award: award, fee: fee, room_id: room_id, date: date},
            dataType: 'json',
            url: '/User/Tool/awardUpdate',
            type: 'get',
            success: function (res) {
                if(res.code == 1){
                    window.location.href = "/User/Tool/award";
                }else{
                    alert(res.msg);
                }
            }
        })
    }
    $("#myModal").on('hide.bs.modal', function () {
        $("#id").val("");
        $("#award").val("");
        $("#fee").val("");
        $("#room_id").val("");
        $("#date").val("");
    });
    function show(e) {
        $("#id").val($(e).attr("data-id"));
        $("#award").val($(e).attr("data-award"));
        $("#fee").val($(e).attr("data-fee"));
        $("#room_id").val($(e).attr("data-roomId"));
        var date = $(e).attr("data-year") + "/" + $(e).attr("data-month");
        $("#date").val(date);
        $('#myModal').modal('show');
    }

    function show_dtl(e) {
        var year = $(e).attr("data-year");
        var month = $(e).attr("data-month");
        var room_id = $(e).attr("data-roomId");
        var name = $(e).attr("data-roomName");
        $.ajax({
            data: {room_id: room_id,month: month,year:year},
            dataType: 'json',
            url: '/User/Tool/ajaxAwardDtl',
            type: 'get',
            success: function (res) {
                $("#myModalLabel2").text(name);
                var table="<table class='table table-hover general-table table-bordered'><tr><th>姓名</th><th>奖金</th></tr>";
                if(res.length > 0){
                    for(i = 0; i< res.length;i++){
                        table += "<tr>";
                        table += "<td>" + res[i]['emp_name'] + "</td>";
                        table += "<td>" + res[i]['award'] + "</td>";
                        table += "</tr>";
                    }
                }else{
                    table += "<tr><td colspan='2'>无纪录</td></tr>";
                }
                table += "</table>";
                $("#myModal2_body").html(table);
                $('#myModal2').modal('show');
            }
        });
        return false;
    }
    function delete_data(id) {
        if(confirm("确定删除？")){
            $.ajax({
                data: {id: id},
                dataType: 'json',
                url: '/User/Tool/awardDelete',
                type: 'get',
                success: function (res) {
                    window.location.reload();
                }
            });
        }
        return false;
    }
    function renew_data(id) {
        if(confirm("确定撤回？")){
            $.ajax({
                data: {id: id},
                dataType: 'json',
                url: '/User/Tool/awardRenew',
                type: 'get',
                success: function (res) {
                    window.location.reload();
                }
            });
        }
        return false;
    }
    function submit_sdate() {
        window.location.href = "/User/Tool/award?sdate=" + $("#sdate").val() + "&room_id=" + "<?php echo I('get.room_id', '', '');?>";
    }
    function download(){
        if(confirm("确定导出？导出后当月不再可分配奖金！")) {
            window.location = '/User/Tool/exportAwardDtl?room_id=' + "<?php echo I('get.room_id', '', '');?>" + "&sdate=" + "<?php echo I('get.sdate', '', '');?>";
        }
        return false;
    }
</script>
<script type="text/javascript" src="/Public/js/laydate/laydate.js"></script>
<style>
    .laydate_table {
        display: none;
    }

    #laydate_hms {
        display: none !important;
    }
</style>
<script type="text/javascript">
    $(".date-picker").bind("click", function () {
        laydate({
            format: 'YYYY/MM',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06', //最大日期
            istime: true,
            istoday: false
        });
        laydate.skin("molv");
    });
    $(".date-picker1").bind("click", function () {
        laydate({
            format: 'YYYYMM',
            max: '2099-06', //最大日期
            istime: true,
            istoday: false
        });
        laydate.skin("molv");
    });
</script>